<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="发起用户" prop="fqyh">
        <el-input
          v-model="queryParams.fqyh"
          placeholder="请输入发起用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ptsp:pttj:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ptsp:pttj:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ptsp:pttj:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ptsp:pttj:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <a>活动参与人数:{{this.xinxi.hdcyrs}}
      推广人数:{{this.xinxi.tgrs}}
      发起拼团数:{{this.xinxi.fqpts}}<br>
      成团数:{{this.xinxi.cts}}
      支付订单额:{{this.xinxi.zfdde}}
      支付人数:{{this.xinxi.zfrs}}</a>
    <el-table v-loading="loading" :data="pttjList" @selection-change="handleSelectionChange">

      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="头像" align="center" prop="tx" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.tx" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="发起用户" align="center" prop="fqyh" />
      <el-table-column label="开团时间" align="center" prop="ktsj" />
      <el-table-column label="拼团人数" align="center" prop="ptrs" />
      <el-table-column label="结束时间" align="center" prop="jssj" />
      <el-table-column label="拼团状态" align="center" prop="ptzt" >
        <el-switch
          style="display: block"
          v-model="form.ptzt"
          active-color="#13ce66"
          inactive-color="#ff4949"
          :active-value="1"
          :inactive-value="0"
          active-text="开启"
          inactive-text="关闭">
        </el-switch>
      </el-table-column>
      <el-table-column label="金额" align="center" prop="je" />
      <el-table-column label="订单编号" align="center" prop="djbh" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ptsp:pttj:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ptsp:pttj:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改拼团统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="头像" prop="tx">
          <image-upload v-model="form.tx"/>
        </el-form-item>
        <el-form-item label="发起用户" prop="fqyh">
          <el-input v-model="form.fqyh" placeholder="请输入发起用户" />
        </el-form-item>
        <el-form-item label="开团时间" prop="ktsj">
          <el-input v-model="form.ktsj" placeholder="请输入开团时间" />
        </el-form-item>
        <el-form-item label="拼团人数" prop="ptrs">
          <el-input v-model="form.ptrs" placeholder="请输入拼团人数" />
        </el-form-item>
        <el-form-item label="结束时间" prop="jssj">
          <el-input v-model="form.jssj" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="拼团状态" prop="ptzt">
          <el-switch
            style="display: block"
            v-model="form.ptzt"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="0"
            active-text="开启"
            inactive-text="关闭">
          </el-switch>
        </el-form-item>
        <el-form-item label="金额" prop="je">
          <el-input v-model="form.je" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="订单编号" prop="djbh">
          <el-input v-model="form.djbh" placeholder="请输入订单编号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { listPttj,count } from "@/api/ptsp/ptsp";
export default {
  name: "Pttj",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      countId:0,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 拼团统计表格数据
      pttjList: [],
      xinxi:{},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fqyh: null,
      },
      // 表单参数
      form: {},
      query:{
        id:null,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    const data=this.$route.query.id;
    console.log(data)
    this.countId=data
    this.query.id=this.countId;
    console.log(this.countId)
    this.getList();
  },
  methods: {
    /** 查询拼团统计列表 */
    getList() {
      console.log(this.countId)
      count(this.query).then(res=>{
        this.pttjList=res;
        this.xinxi=this.pttjList[0]
        this.loading=false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tx: null,
        fqyh: null,
        ktsj: null,
        ptrs: null,
        jssj: null,
        ptzt: null,
        hdcyrs: null,
        tgrs: null,
        fqpts: null,
        cts: null,
        zfdde: null,
        zfrs: null,
        pid: null,
        je: null,
        djbh: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      this.form=row;
      this.open=true;
    },
  }
};
</script>
